# ！/usr/bin/env python
# -*- coding = utf-8 -*-
# ================================================
# @Time  :2021/8/2 14:50
# @Author:tyh
# @File  :server.py
# @Phone :13926528314
# ================================================
import json
import logging

from flask import Flask, request
from flask_restful import Resource, Api
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS

app = Flask(__name__)
api = Api(app)
CORS(app, supports_credentials=True)
username = "root"
pwd = "123456"
ip = "42.192.73.147"
port = "3306"
database = "test_platform"
app.config['SQLALCHEMY_DATABASE_URI'] = f'mysql+pymysql://{username}:{pwd}@{ip}:{port}/{database}?charset=utf8'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.logger.setLevel(logging.DEBUG)
db = SQLAlchemy(app)


def router():
    # 路由管理
    from apis.testcase import TestCaseServer
    from apis.task import TaskServer
    api.add_resource(TestCaseServer, "/testcase")
    api.add_resource(TaskServer, "/task")


if __name__ == '__main__':
    # 接口服务，路由
    # db.create_all()
    # 添加路由，将resource挂在flask服务上
    router()
    app.run(debug=True)
